package com.shangxian.giveithome.controller;

import com.shangxian.giveithome.annoaction.CheckLoginStatus;
import com.shangxian.giveithome.entity.community.Attention;
import com.shangxian.giveithome.result.Result;
import com.shangxian.giveithome.service.AttentionService;
import com.shangxian.giveithome.service.CollectionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/attention")
public class AttentionController {
    @Autowired
    private AttentionService attentionService;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private CollectionService collectionService;

    @PostMapping("/attentionUser")
    @ApiOperation(value = "关注用户")
    @CheckLoginStatus
    public Result attentionUser(@RequestBody Attention attention){
        attentionService.attentionUser(attention,request);
        return Result.success();
    }

    @DeleteMapping("/cancelAttention")
    @ApiOperation(value = "取消关注")
    @CheckLoginStatus
    public Result cancelAttention(@RequestParam("id") Long id){
        attentionService.cancelAttention(id, request);
        return Result.success();
    }

    @GetMapping("/findAllAttentionUser")
    @ApiOperation(value = "查询所有关注的用户")
    @CheckLoginStatus
    public Result findAllAttentionUser(@PageableDefault(page = 0, size = 10)Pageable pageable){

        return  Result.success(attentionService.findAllAttentionUser(request,pageable));
    }


}
